*** Paper: 			Does The World Trade Organization Enable Biosecurity and Trade for Importers and Exporters?
*** Authors: Linda Fernandez and Monica Das
*** Date:    		November 9, 2023
*** Last updated:   February 21, 2024
*** Description:	STATA codes for all Figures in the paper

******************************************************
********** Figure 1                                ****
*******************************************************
///Download STATA file "wd.dta" from the Harvard Dataverse  
///Change directory to appropriate folder
//import STATA dataset "wd.dta" 

use "wd.dta", clear


replace Country = "S Africa" if Country == "South Africa"
replace Country = "Tanzania" if Country == "United Republic of Tanzania"
replace Country = "PapuaNewGuinea" if Country == "Papua New Guinea"

/*
generate region1 =0
///East, South and Western Asia
replace region1 = 1 if region ==1
///Europe and Central Asia
generate region2 =0
replace region2 = 1 if region == 2
///Latin America and the Caribbean
generate region3 =0
replace region3 = 1 if region == 3
////Middle East and Africa
generate region4 =0
replace region4 = 1 if region == 4


/*generate dummy variables for region*/
generate regioncode = 0
replace regioncode = 1 if region1 == 1
replace regioncode = 2 if region2 == 1
replace regioncode = 3 if region3 == 1
replace regioncode = 4 if region4 == 1
tab regioncode


/*re-label region variable*/
label define region 1 "East South & West Asia" 2 "Europe and Central Asia" 3 "Latin America and the Caribbean" 4 "Middle East and Africa"
label values regioncode region
*/

/*making bar codes*/
/*install only once*/
/*ssc install splitvallabels*/
splitvallabels regioncode, length(10)
graph hbar (mean) AE_GDP, over(Country,  sort(AE_GDP) label(labsize(vsmall)) ) over(regioncode, label(labsize(small)) relabel(`r(relabel)')) nofill scheme(sj) ytitle("Average AE/GDP by Country", size(medium)) yline(0.8,lcolor(red) lpattern(dash))
graph save Graph "fig1A.gph", replace

splitvallabels regioncode, length(10)
graph hbar (mean) GNIpercap, over(Country,  sort(GNIpercap) label(labsize(vsmall)) ) over(regioncode, label(labsize(small)) relabel(`r(relabel)')) nofill scheme(sj) ytitle("Average GNI/capita", size(medium)) yline(4793,lcolor(red) lpattern(dash))
graph save Graph "fig1B.gph", replace

splitvallabels regioncode, length(10)
graph hbar (mean) ETI, over(Country,  sort(ETI) label(labsize(vsmall)) ) over(regioncode, label(labsize(small)) relabel(`r(relabel)')) nofill scheme(sj) ytitle("Average Enabling Trade Index by Country", size(medium)) yline(3.78,lcolor(red) lpattern(dash))
graph save Graph "fig1C.gph", replace

graph combine "fig1A.gph" "fig1B.gph" "fig1C.gph", rows(2)

******************************************************
********** Figure 2                                ****
*******************************************************
use "wd.dta", clear


//random coefficient model by region
//with Interaction terms

rename ETI X
gen obs = _n
order obs 
tabulate ccode, gen(cty_dum)
/*Please save this data in your own computer 
and refer accordingly in following lines of code*/
save "bootdata.dta", replace


******************************************************************
***********BOOTSTRAP CONFIDENCE BANDS*****************************
******************************************************************
set seed 101016
local n = _N 			 			
set obs `n'
generate store_sd1 = .
generate store_sd2 = .
generate store_sd3 = .


quietly { 
	forvalues i = 1(1)759 {			
		preserve
		use bootdata.dta, clear
		bsample, cluster(ccode)
		regress AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div cty_dum1 - cty_dum33 
		matrix beta1 = e(b)
		matrix list beta1
		generate Y1 = beta1[1,1]+beta1[1,4]* X
		summ Y1 
		local sd_got1=r(sd)
		regress AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur cty_dum1 - cty_dum33
		matrix beta2 = e(b)
		matrix list beta2
		generate Y2 = beta2[1,1]+beta2[1,4]* X
		summ Y2 
		local sd_got2=r(sd)
		regress AgrExport lnTAvalue Manu_sh lnRGDP Value_Int resid_Value cty_dum1 - cty_dum33
		matrix beta3 = e(b)
		matrix list beta3
		generate Y3 = beta3[1,1]+beta3[1,4]* X
		summ Y3 
		local sd_got3=r(sd)
		restore
		replace store_sd1 = `sd_got1' in `i'
		replace store_sd2 = `sd_got2' in `i'
		replace store_sd3 = `sd_got3' in `i'
		}
}
display "end"

summ store_sd1  			/*Get Std Deviation*/
generate sd_boot1 = r(mean)

summ store_sd2  			/*Get Std Deviation*/
generate sd_boot2 = r(mean)

summ store_sd3  			/*Get Std Deviation*/
generate sd_boot3 = r(mean)
	


******************************************************************************
********UPPER and LOWER BOUNDS***********************************************
******************************************************************************
//Diversification
regress AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div cty_dum1 - cty_dum33 
matrix beta1 = e(b)
generate Y1 = beta1[1,1]+beta1[1,4]* X
		
generate Y1_upper = Y1 + 1.282*sd_boot1
generate Y1_lower = Y1 - 1.282*sd_boot1
///solution point
display (1.282*sd_boot1 - beta1[1,1])/beta1[1,4]

//Duration
regress AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur cty_dum1 - cty_dum33
matrix beta2 = e(b)
generate Y2 = beta2[1,1]+beta2[1,4]* X

generate Y2_upper = Y2 + 1.282*sd_boot2
generate Y2_lower = Y2 - 1.282*sd_boot2
///solution point 
display (1.282*sd_boot2 - beta2[1,1])/beta2[1,4]

//Value
regress AgrExport lnTAvalue Manu_sh lnRGDP Value_Int resid_Value cty_dum1 - cty_dum33
matrix beta3 = e(b)
generate Y3 = beta3[1,1]+beta3[1,4]* X
		
generate Y3_upper = Y3 + 1.282*sd_boot3
generate Y3_lower = Y3 - 1.282*sd_boot3
///solution point 
display (1.282*sd_boot3 - beta3[1,1])/beta3[1,4]


twoway (scatter Y1 X, sort msize(small)) (line Y1_upper X, sort lpattern(dash)) (line Y1_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) ytitle(diversification) xtitle(ETI) legend(off) title(II.A  Diversification)
graph save Graph "fig2A.gph", replace

twoway (scatter Y2 X, sort msize(tiny)) (line Y2_upper X, sort lpattern(dash)) (line Y2_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) ytitle(duration) xtitle(ETI) legend(off) title(II.B Duration)
graph save Graph "fig2B.gph", replace

twoway (scatter Y3 X, sort msize(tiny)) (line Y3_upper X, sort lpattern(dash)) (line Y3_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) ytitle(value) xtitle(ETI) legend(off) title(II.C Value)
graph save Graph "fig2C.gph", replace

graph combine "fig2A.gph" "fig2B.gph" "fig2C.gph"

********************************************************
********** Figure 3                               *****
********************************************************

use "wd.dta", clear
//random coefficient model by AEshare
//with Interaction terms

rename ETI X


///grouping by observations
gen AEcode = 0
egen median1 = median(AE_GDP)
replace AEcode = 1 if AE_GDP >= median1
replace AEcode = . if AE_GDP == .

gen obs = _n
order obs 
save "bootdata.dta", replace

*********************************************************************************
***********Diversification
******************************************************************************

******************************************************************
***********BOOTSTRAP CONFIDENCE BANDS*****************************
******************************************************************
set seed 101016

//clear
local n = _N			 			
set obs `n'
generate store_sd1 = .
generate store_sd2 = .

quietly { 
	forvalues i = 1(1)759 {			
		preserve
		use bootdata.dta, clear
		bsample
		xtrc AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div, i( AEcode) betas
		matrix beta = e(beta_ps)
		matrix list beta
		generate Y1 = beta[1,1]+beta[1,4]* X
		summ Y1 
		local sd_got1=r(sd)
		generate Y2 = beta[2,1]+beta[2,4]* X
		summ Y2
		local sd_got2=r(sd)
		restore
		replace store_sd1 = `sd_got1' in `i'
		replace store_sd2 = `sd_got2' in `i'
	}
}
display "end"

summ store_sd1  			/*Get Std Deviation*/
generate sd_boot1 = r(mean)

summ store_sd2  			/*Get Std Deviation*/
generate sd_boot2 = r(mean)


******************************************************************************
********UPPER and LOWER BOUNDS***********************************************
******************************************************************************
xtrc AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div, i( AEcode) betas
matrix beta = e(beta_ps)
generate Y1 = beta[1,1]+beta[1,4]*X
generate Y2 = beta[2,1]+beta[2,4]*X

generate Y1_upper = Y1 + 1.282*sd_boot1
generate Y1_lower = Y1 - 1.282*sd_boot1
///solution point
display (1.282*sd_boot1 - beta[1,1])/beta[1,4]

generate Y2_upper = Y2 + 1.282*sd_boot2
generate Y2_lower = Y2 - 1.282*sd_boot2
///solution point
display (1.282*sd_boot2 - beta[2,1])/beta[2,4]

*****************************************************
***  Figure - 3, row -1                          ****
*****************************************************

twoway (scatter Y1 X, sort msize(small)) (line Y1_upper X, sort lpattern(dash)) (line Y1_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) ytitle(diversification, size(large)) xtitle(ETI) legend(off) title (Below Median)
graph save Graph "fig3A1.gph", replace

twoway (scatter Y2 X, sort msize(small))(line Y2_upper X, sort lpattern(dash)) (line Y2_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) ytitle(diversification, size(large)) xtitle(ETI) legend(off) title (Above Median)
graph save Graph "fig3A2.gph", replace


*******************************************************************************
*******Duration
*********************************************************************************

******************************************************************
***********BOOTSTRAP CONFIDENCE BANDS*****************************
******************************************************************
drop store_sd1 store_sd2 sd_boot1 sd_boot2 Y1 Y2 Y1_upper Y1_lower Y2_upper Y2_lower 

set seed 101016
local n = _N 			 			
set obs `n'
generate store_sd1 = .
generate store_sd2 = .

quietly { 
	forvalues i = 1(1)759 {			
		preserve
		use bootdata.dta, clear
		bsample
		xtrc AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur, i( AEcode) betas
		matrix beta = e(beta_ps)
		matrix list beta
		generate Y1 = beta[1,1]+beta[1,4]* X
		summ Y1 
		local sd_got1=r(sd)
		generate Y2 = beta[2,1]+beta[2,4]* X
		summ Y2
		local sd_got2=r(sd)
		restore
		replace store_sd1 = `sd_got1' in `i'
		replace store_sd2 = `sd_got2' in `i'
	}
}
display "end"

summ store_sd1  			/*Get Std Deviation*/
generate sd_boot1 = r(mean)

summ store_sd2  			/*Get Std Deviation*/
generate sd_boot2 = r(mean)



******************************************************************************
********UPPER and LOWER BOUNDS***********************************************
******************************************************************************
xtrc AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur, i( AEcode) betas
matrix beta = e(beta_ps)
generate Y1 = beta[1,1]+beta[1,4]*X
generate Y2 = beta[2,1]+beta[2,4]*X

generate Y1_upper = Y1 + 1.282*sd_boot1
generate Y1_lower = Y1 - 1.282*sd_boot1
///solution point
display (1.282*sd_boot1 - beta[1,1])/beta[1,4]

generate Y2_upper = Y2 + 1.282*sd_boot2
generate Y2_lower = Y2 - 1.282*sd_boot2
///solution point
display (1.282*sd_boot2 - beta[2,1])/beta[2,4]
***************************************************
*****      Figure - 3, row -2                 *****
***************************************************
twoway (scatter Y1 X, sort msize(tiny)) (line Y1_upper X, sort lpattern(dash)) (line Y1_lower X, sort lpattern(dash)), legend(off)  yline(0, lpattern(solid) lcolor(black)) ytitle(duration, size(large)) xtitle(ETI) title(Below Median)
graph save Graph "fig3B1.gph", replace


twoway (scatter Y2 X, sort msize(tiny))(line Y2_upper X, sort lpattern(dash)) (line Y2_lower X, sort lpattern(dash)), legend(off) yline(0, lpattern(solid) lcolor(black)) ytitle(duration, size(large)) xtitle(ETI) title(Above Median)
graph save Graph "fig3B2.gph", replace

********************************************************************************
*********Value
********************************************************************************

******************************************************************
***********BOOTSTRAP CONFIDENCE BANDS*****************************
******************************************************************
drop store_sd1 store_sd2 sd_boot1 sd_boot2 Y1 Y2 Y1_upper Y1_lower Y2_upper Y2_lower 

set seed 101016
local n = _N 
set obs `n'
generate store_sd1 = .
generate store_sd2 = .

quietly { 
	forvalues i = 1(1)759 {
		preserve
		use bootdata.dta, clear
		bsample
		xtrc AgrExport lnTAvalue Manu_sh lnRGDP Value_Int resid_Value, i( AEcode) betas
		matrix beta = e(beta_ps)
		matrix list beta
		generate Y1 = beta[1,1]+beta[1,4]* X
		summ Y1 
		local sd_got1=r(sd)
		generate Y2 = beta[2,1]+beta[2,4]* X
		summ Y2
		local sd_got2=r(sd)
		restore
		replace store_sd1 = `sd_got1' in `i'
		replace store_sd2 = `sd_got2' in `i'
 
	}
}
display "end"

summ store_sd1  			/*Get Std Deviation*/
generate sd_boot1 = r(mean)

summ store_sd2  			/*Get Std Deviation*/
generate sd_boot2 = r(mean)


******************************************************************************
********UPPER and LOWER BOUNDS***********************************************
******************************************************************************
xtrc AgrExport lnTAvalue Manu_sh lnRGDP Value_Int resid_Value, i( AEcode) betas
matrix beta = e(beta_ps)
generate Y1 = beta[1,1]+beta[1,4]*X
generate Y2 = beta[2,1]+beta[2,4]*X

generate Y1_upper = Y1 + 1.282*sd_boot1
generate Y1_lower = Y1 - 1.282*sd_boot1
///solution point
display (1.282*sd_boot1 - beta[1,1])/beta[1,4]

generate Y2_upper = Y2 + 1.282*sd_boot2
generate Y2_lower = Y2 - 1.282*sd_boot2
///solution point
display (1.282*sd_boot2 - beta[2,1])/beta[2,4]

***************************************************
*****      Figure - 3, row -3                 *****
***************************************************

twoway (scatter Y1 X, sort msize(small)) (line Y1_upper X, sort lpattern(dash)) (line Y1_lower X, sort lpattern(dash)),yline(0, lpattern(solid) lcolor(black)) legend(off) ytitle(value, size(large)) xtitle(ETI) title(Below Median)
graph save Graph "fig3C1.gph", replace

twoway (scatter Y2 X, sort msize(small))(line Y2_upper X, sort lpattern(dash)) (line Y2_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) legend(off) ytitle(value, size(large)) xtitle(ETI) title(Above Median)
graph save Graph "fig3C2.gph", replace

drop store_sd1 store_sd2 sd_boot1 sd_boot2 Y1 Y2 Y1_upper Y1_lower Y2_upper Y2_lower 

graph combine "fig3A1.gph" "fig3A2.gph" "fig3B1.gph" "fig3B2.gph" "fig3C1.gph" "fig3C2.gph", rows(3)

*********************************************************
********  Figure 4                                 ******
*********************************************************

use "wd.dta", clear
//random coefficient model by region
//with Interaction terms

rename ETI X
gen obs = _n
order obs 
save "bootdata.dta", replace


*********************************************************************************
***********Diversification
******************************************************************************

******************************************************************
***********BOOTSTRAP CONFIDENCE BANDS*****************************
******************************************************************
set seed 101016
local n = _N 			 			/*reps*/
set obs `n'
generate store_sd1 = .
generate store_sd2 = .
generate store_sd3 = .
generate store_sd4 = .

quietly { 
	forvalues i = 1(1)759 {			/*reps*/
		preserve
		use bootdata.dta, clear
		bsample
		xtrc AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div, i(region) betas
		matrix beta = e(beta_ps)
		matrix list beta
		generate Y1 = beta[1,1]+beta[1,4]* X
		summ Y1 
		local sd_got1=r(sd)
		generate Y2 = beta[2,1]+beta[2,4]* X
		summ Y2 
		local sd_got2=r(sd)
		generate Y3 = beta[3,1]+beta[3,4]* X
		summ Y3 
		local sd_got3=r(sd)
		generate Y4 = beta[4,1]+beta[4,4]* X
		summ Y4 
		local sd_got4=r(sd)
		restore
		replace store_sd1 = `sd_got1' in `i'
		replace store_sd2 = `sd_got2' in `i'
		replace store_sd3 = `sd_got3' in `i'
		replace store_sd4 = `sd_got4' in `i'
	}
}
display "end"

summ store_sd1  			/*Get Std Deviation*/
generate sd_boot1 = r(mean)

summ store_sd2  			/*Get Std Deviation*/
generate sd_boot2 = r(mean)

summ store_sd3  			/*Get Std Deviation*/
generate sd_boot3 = r(mean)

summ store_sd4  			/*Get Std Deviation*/
generate sd_boot4 = r(mean)



******************************************************************************
********UPPER and LOWER BOUNDS***********************************************
******************************************************************************
//Diversification
xtrc AgrExport TACommlag Manu_sh lnRGDP Diversification_Int resid_Div, i(region) betas
matrix beta = e(beta_ps)
generate Y1 = beta[1,1]+beta[1,4]*X
generate Y2 = beta[2,1]+beta[2,4]*X
generate Y3 = beta[3,1]+beta[3,4]*X
generate Y4 = beta[4,1]+beta[4,4]*X

generate Y1_upper = Y1 + 1.282*sd_boot1
generate Y1_lower = Y1 - 1.282*sd_boot1
///solution point
display (1.282*sd_boot1 - beta[1,1])/beta[1,4]

generate Y2_upper = Y2 + 1.282*sd_boot2
generate Y2_lower = Y2 - 1.282*sd_boot2
///solution point
display (1.282*sd_boot2 - beta[2,1])/beta[2,4]

generate Y3_upper = Y3 + 1.282*sd_boot3
generate Y3_lower = Y3 - 1.282*sd_boot3
///solution point
display (1.282*sd_boot3 - beta[3,1])/beta[3,4]

generate Y4_upper = Y4 + 1.282*sd_boot4
generate Y4_lower = Y4 - 1.282*sd_boot4
///solution point
display (1.282*sd_boot4 - beta[4,1])/beta[4,4]


twoway (scatter Y1 X, sort msize(small)) (line Y1_upper X, sort lpattern(dash)) (line Y1_lower X, sort lpattern(dash)),yline(0, lpattern(solid) lcolor(black)) ytitle(diversification) xtitle(ETI) title(East West & South Asia) legend(off)
graph save Graph "fig4A.gph", replace

twoway (scatter Y2 X, sort msize(small))(line Y2_upper X, sort lpattern(dash)) (line Y2_lower X, sort lpattern(dash)) , yline(0, lpattern(solid) lcolor(black)) ytitle(diversification) xtitle(ETI) title(Europe and Central Asia) legend(off)
graph save Graph "fig4B.gph", replace

twoway (scatter Y3 X, sort msize(small)) (line Y3_upper X, sort lpattern(dash)) (line Y3_lower X, sort lpattern(dash)) , yline(0, lpattern(solid) lcolor(black)) ytitle(diversification) xtitle(ETI) title(Latin America and the Caribbean) legend(off)
graph save Graph "fig4C.gph", replace

twoway (scatter Y4 X, sort msize(small)) (line Y4_upper X, sort lpattern(dash)) (line Y4_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) ytitle(diversification) xtitle(ETI) title(Middle East and Africa) legend(off)
graph save Graph "fig4D.gph", replace

graph combine "fig4A.gph" "fig4B.gph" "fig4C.gph" "fig4D.gph", rows(2)
*********************************************************
********  Figure 5                                 ******
*********************************************************


*******************************************************************************
*******Duration
*********************************************************************************

******************************************************************
***********BOOTSTRAP CONFIDENCE BANDS*****************************
******************************************************************
drop store_sd1 store_sd2 store_sd3 store_sd4 sd_boot1 sd_boot2 sd_boot3 sd_boot4 Y1 Y2 Y3 Y4 Y1_upper Y1_lower Y2_upper Y2_lower Y3_upper Y3_lower Y4_upper Y4_lower 

set seed 101016
local n = _N 			 			/*reps*/
set obs `n'
generate store_sd1 = .
generate store_sd2 = .
generate store_sd3 = .
generate store_sd4 = .

quietly { 
	forvalues i = 1(1)759 {			/*reps*/
		preserve
		use bootdata.dta, clear
		bsample
		xtrc AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur, i(region) betas
		matrix beta = e(beta_ps)
		matrix list beta
		generate Y1 = beta[1,1]+beta[1,4]* X
		summ Y1 
		local sd_got1=r(sd)
		generate Y2 = beta[2,1]+beta[2,4]* X
		summ Y2 
		local sd_got2=r(sd)
		generate Y3 = beta[3,1]+beta[3,4]* X
		summ Y3 
		local sd_got3=r(sd)
		generate Y4 = beta[4,1]+beta[4,4]* X
		summ Y4 
		local sd_got4=r(sd)
		restore
		replace store_sd1 = `sd_got1' in `i'
		replace store_sd2 = `sd_got2' in `i'
		replace store_sd3 = `sd_got3' in `i'
		replace store_sd4 = `sd_got4' in `i'
	}
}
display "end"

summ store_sd1  			/*Get Std Deviation*/
generate sd_boot1 = r(mean)

summ store_sd2  			/*Get Std Deviation*/
generate sd_boot2 = r(mean)

summ store_sd3  			/*Get Std Deviation*/
generate sd_boot3 = r(mean)

summ store_sd4  			/*Get Std Deviation*/
generate sd_boot4 = r(mean)

******************************************************************************
********UPPER and LOWER BOUNDS***********************************************
******************************************************************************
//Duration
xtrc AgrExport TAduration Manu_sh lnRGDP Duration_Int resid_Dur, i(region) betas
matrix beta = e(beta_ps)
generate Y1 = beta[1,1]+beta[1,4]*X
generate Y2 = beta[2,1]+beta[2,4]*X
generate Y3 = beta[3,1]+beta[3,4]*X
generate Y4 = beta[4,1]+beta[4,4]*X


generate Y1_upper = Y1 + 1.282*sd_boot1
generate Y1_lower = Y1 - 1.282*sd_boot1
///solution point
display (1.282*sd_boot1 - beta[1,1])/beta[1,4]

generate Y2_upper = Y2 + 1.282*sd_boot2
generate Y2_lower = Y2 - 1.282*sd_boot2
///solution point
display (1.282*sd_boot2 - beta[2,1])/beta[2,4]

generate Y3_upper = Y3 + 1.282*sd_boot3
generate Y3_lower = Y3 - 1.282*sd_boot3
///solution point
display (1.282*sd_boot3 - beta[3,1])/beta[3,4]

generate Y4_upper = Y4 + 1.282*sd_boot4
generate Y4_lower = Y4 - 1.282*sd_boot4
///solution point
display (1.282*sd_boot4 - beta[4,1])/beta[4,4]


twoway (scatter Y1 X, sort msize(small)) (line Y1_upper X, sort lpattern(dash)) (line Y1_lower X, sort lpattern(dash)),  ytitle(duration) xtitle(ETI) title(East West & South Asia) legend(off)
graph save Graph "fig5A.gph", replace

twoway (scatter Y2 X, sort msize(small))(line Y2_upper X, sort lpattern(dash)) (line Y2_lower X, sort lpattern(dash)) , yline(0, lpattern(solid) lcolor(black)) ytitle(duration) xtitle(ETI) title(Europe and Central Asia) legend(off)
graph save Graph "fig5B.gph", replace

twoway (scatter Y3 X, sort msize(small)) (line Y3_upper X, sort lpattern(dash)) (line Y3_lower X, sort lpattern(dash)) , yline(0, lpattern(solid) lcolor(black)) ytitle(duration) xtitle(ETI) title(Latin America and the Caribbean) legend(off)
graph save Graph "fig5C.gph", replace

twoway (scatter Y4 X, sort msize(small)) (line Y4_upper X, sort lpattern(dash)) (line Y4_lower X, sort lpattern(dash)), yline(0, lpattern(solid) lcolor(black)) ytitle(duration) xtitle(ETI) title(Middle East and Africa) legend(off)
graph save Graph "fig5D.gph", replace

graph combine "fig5A.gph" "fig5B.gph" "fig5C.gph" "fig5D.gph", rows(2)

*********************************************************
********  Figure 6                                 ******
*********************************************************



********************************************************************************
*********Value four regions
********************************************************************************


******************************************************************
***********BOOTSTRAP CONFIDENCE BANDS*****************************
******************************************************************
drop store_sd1 store_sd2 store_sd3 store_sd4 sd_boot1 sd_boot2 sd_boot3 sd_boot4 Y1 Y2 Y3 Y4 Y1_upper Y1_lower Y2_upper Y2_lower Y3_upper Y3_lower Y4_upper Y4_lower 

set seed 101016
local n = _N 			 			/*reps*/
set obs `n'
generate store_sd1 = .
generate store_sd2 = .
generate store_sd3 = .
generate store_sd4 = .

quietly { 
	forvalues i = 1(1)759 {			/*reps*/
		preserve
		use bootdata.dta, clear
		bsample
		xtrc AgrExport lnTAvalue Manu_sh lnRGDP Value_Int resid_Value, i(region) betas
		matrix beta = e(beta_ps)
		matrix list beta
		generate Y1 = beta[1,1]+beta[1,4]* X
		summ Y1 
		local sd_got1=r(sd)
		generate Y2 = beta[2,1]+beta[2,4]* X
		summ Y2 
		local sd_got2=r(sd)
		generate Y3 = beta[3,1]+beta[3,4]* X
		summ Y3 
		local sd_got3=r(sd)
		generate Y4 = beta[4,1]+beta[4,4]* X
		summ Y4 
		local sd_got4=r(sd)
		restore
		replace store_sd1 = `sd_got1' in `i'
		replace store_sd2 = `sd_got2' in `i'
		replace store_sd3 = `sd_got3' in `i'
		replace store_sd4 = `sd_got4' in `i'
	}
}
display "end"

summ store_sd1  			/*Get Std Deviation*/
generate sd_boot1 = r(mean)

summ store_sd2  			/*Get Std Deviation*/
generate sd_boot2 = r(mean)

summ store_sd3  			/*Get Std Deviation*/
generate sd_boot3 = r(mean)

summ store_sd4  			/*Get Std Deviation*/
generate sd_boot4 = r(mean)


******************************************************************************
********UPPER and LOWER BOUNDS***********************************************
******************************************************************************
//Value
xtrc AgrExport lnTAvalue Manu_sh lnRGDP Value_Int resid_Value, i(region) betas
matrix beta = e(beta_ps)
generate Y1 = beta[1,1]+beta[1,4]*X
generate Y2 = beta[2,1]+beta[2,4]*X
generate Y3 = beta[3,1]+beta[3,4]*X
generate Y4 = beta[4,1]+beta[4,4]*X

generate Y1_upper = Y1 + 1.282*sd_boot1
generate Y1_lower = Y1 - 1.282*sd_boot1
///solution point
display (1.282*sd_boot1 - beta[1,1])/beta[1,4]

generate Y2_upper = Y2 + 1.282*sd_boot2
generate Y2_lower = Y2 - 1.282*sd_boot2
///solution point
display (1.282*sd_boot2 - beta[2,1])/beta[2,4]

generate Y3_upper = Y3 + 1.282*sd_boot3
generate Y3_lower = Y3 - 1.282*sd_boot3
///solution point
display (1.282*sd_boot3 - beta[3,1])/beta[3,4]

generate Y4_upper = Y4 + 1.282*sd_boot4
generate Y4_lower = Y4 - 1.282*sd_boot4
///solution point
display (1.282*sd_boot4 - beta[4,1])/beta[4,4]



twoway (scatter Y1 X, sort msize(small)) (line Y1_upper X, sort lpattern(dash)) (line Y1_lower X, sort lpattern(dash)),yline(0, lpattern(solid) lcolor(black)) ytitle(value) xtitle(ETI) title(East West & South Asia) legend(off)
graph save Graph "fig6A.gph", replace

twoway (scatter Y2 X, sort msize(small))(line Y2_upper X, sort lpattern(dash)) (line Y2_lower X, sort lpattern(dash)) ,yline(0, lpattern(solid) lcolor(black)) ytitle(value) xtitle(ETI) title(Europe and Central Asia) legend(off)
graph save Graph "fig6B.gph", replace

twoway (scatter Y3 X, sort msize(small)) (line Y3_upper X, sort lpattern(dash)) (line Y3_lower X, sort lpattern(dash)),yline(0, lpattern(solid) lcolor(black)) ytitle(value) xtitle(ETI) title(Latin America and the Caribbean) legend(off)
graph save Graph "fig6C.gph", replace

twoway (scatter Y4 X, sort msize(small)) (line Y4_upper X, sort lpattern(dash)) (line Y4_lower X, sort lpattern(dash)), ytitle(value) xtitle(ETI) title(Middle East and Africa) legend(off)
graph save Graph "fig6D.gph", replace

graph combine "fig6A.gph" "fig6B.gph" "fig6C.gph" "fig6D.gph", rows(2)



